package com.ruoyi.project.personal.lifephoto.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.personal.lifephoto.domain.UserLifePhoto;
import com.ruoyi.project.personal.lifephoto.service.IUserLifePhotoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 生活照Controller
 * 
 * @author wyh
 * @date 2024-06-16
 */
@RestController
@RequestMapping("/personal/photo")
public class UserLifePhotoController extends BaseController
{
    @Autowired
    private IUserLifePhotoService userLifePhotoService;

    /**
     * 查询生活照列表
     */
    @PreAuthorize("@ss.hasPermi('personal:photo:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserLifePhoto userLifePhoto)
    {
        //非管理部门限制用户只能查看本部门提交的申请
        Long deptId = SecurityUtils.getDeptId();
        if(deptId != 103L){
            userLifePhoto.setTopInviterId(SecurityUtils.getUserId());
        }

        startPage();
        List<UserLifePhoto> list = userLifePhotoService.selectUserLifePhotoList(userLifePhoto);
        return getDataTable(list);
    }

    /**
     * 导出生活照列表
     */
    @PreAuthorize("@ss.hasPermi('personal:photo:export')")
    @Log(title = "生活照", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserLifePhoto userLifePhoto)
    {
        List<UserLifePhoto> list = userLifePhotoService.selectUserLifePhotoList(userLifePhoto);
        ExcelUtil<UserLifePhoto> util = new ExcelUtil<UserLifePhoto>(UserLifePhoto.class);
        util.exportExcel(response, list, "生活照数据");
    }

    /**
     * 获取生活照详细信息
     */
    @PreAuthorize("@ss.hasPermi('personal:photo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userLifePhotoService.selectUserLifePhotoById(id));
    }

    /**
     * 新增生活照
     */
    @PreAuthorize("@ss.hasPermi('personal:photo:add')")
    @Log(title = "生活照", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserLifePhoto userLifePhoto)
    {
        return toAjax(userLifePhotoService.insertUserLifePhoto(userLifePhoto));
    }

    /**
     * 修改生活照
     */
    @PreAuthorize("@ss.hasPermi('personal:photo:edit')")
    @Log(title = "生活照", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserLifePhoto userLifePhoto)
    {
        return toAjax(userLifePhotoService.updateUserLifePhoto(userLifePhoto));
    }

    /**
     * 删除生活照
     */
    @PreAuthorize("@ss.hasPermi('personal:photo:remove')")
    @Log(title = "生活照", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userLifePhotoService.deleteUserLifePhotoByIds(ids));
    }
}
